package com.example.rsa;

import java.io.FileInputStream;
import java.io.InputStream;
import java.security.PrivateKey;
import java.security.PublicKey;

public class RSATest {
	// base64 code
	static String PUCLIC_KEY = "hMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3N8LJFqlsa6loCgFpgZVMr/SxDMQY7pr0euNQfh2g+UVPbB0MGhoc7nWL0FQhCgDedbjQw/nGFStFx7W1+0o1oRTYu5ebNVivZSobraUv7LJvwT8O66Zs8cxbKLqQ/nE/WwJvXomSIckH6R8iOUO8/QT9kv6/L0Uma3qA07pmDQIDAQAB";
	
	static String PRIVATE_KEY = "MIICXQIBAAKBgQC3N8LJFqlsa6loCgFpgZVMr/SxDMQY7pr0euNQfh2g+UVPbB0MGhoc7nWL0FQhCgDedbjQw/nGFStFx7W1+0o1oRTYu5ebNVivZSobraUv7LJvwT8O66Zs8cxbKLqQ/nE/WwJvXomSIckH6R8iOUO8/QT9kv6/L0Uma3qA07pmDQIDAQABAoGBAKba3UWModbfZXQeSJLxNCqWw9zJp3ydL/keQQ35DLqgyIJAD2QKEWXvtJUTsMo19fyicSGOmFXQyYvPCKkmpLkOMAj1XaNpSMtSrcMx+gC01PO6Ey9rsUxW1g3ufpqbEk9E3a5AtCS0I61nbUpRL6rqMtR5o2wcNR3TLtJt7pjxAkEA7hlFJKU1zWGpOvvkJDnHc2NOCEJoGjqCR9wwv96+/xAykl2laI6WvEbbhjoO0+8+d17oigjhneS52UKFcfqw7wJBAMT+MCQ5TYLQlvjrBaDMqOdLsqtaDE6CpkrgwV820QMvHOo3R4XduSbrA2tOr9t2/x+FzF971lRGdPFIch9UYMMCQQCZtO6SDaWCBP3++gX57OL5dq41XsldxU+9nERMWTvr5UUAgDv8F7Dvsr6dFHXmE5i77yUnlzwvdi0UOIF1Z2U5AkBVwyRKYPgx34Ya0JcerntKV1Zt60I4XADx0G/feAn/DN/VyENHMISPQPm4GgXN0jy4CJQ1bcCd6B65fQTSRvXpAkA2Vv5yXzeKDls/AyxHEoros/VYftVc1HOFC++q13RwNH2rnlRT8FMTFEqL9MYRqvvYAFf5VmH0M1Nx5t4LRN+l";

	public static void main(String[] args) throws Exception {
		String source = "zxp";
		InputStream publicIS = new FileInputStream("C:\\rsa_public_key.pem");
		InputStream privateIS = new FileInputStream("C:\\pkcs8_rsa_private_key.pem");
		// PublicKey publicKey = RSAUtils.loadPublicKey(PUCLIC_KEY);
		PublicKey publicKey = RSAUtils.loadPublicKey(publicIS);
		// PrivateKey privateKey = RSAUtils.loadPrivateKey(PRIVATE_KEY);
		PrivateKey privateKey = RSAUtils.loadPrivateKey(privateIS);
		byte[] b1 = RSAUtils.encryptData(source.getBytes(), publicKey);
		System.out.println(">>>"+ new String(RSAUtils.decryptData(b1, privateKey)));
	}
}
